import * as types from "../types/addressListTypes";

const initialState = {
  addressList: [],
  loading: false,
  initing: true,
  error: undefined,
};

export default function addressListReducer(state = initialState, action) {
  switch (action.type) {
    case types.ADDRESSLIST_INITING:
      return {
        ...state,
      };
    case types.ADDRESSLIST_DONE:
      return {
        ...state,
        initing: false,
        loading: false,
        addressList: action.addressList,
      };
    case types.ADDRESSLIST_ERROR:
      return {
        ...state,
        initing: false,
        loading: false,
        error: action.error,
      };
    case types.ADDRESSLIST_LOADING:
      return {
        ...state,
        loading: true,
      };
    case types.ADDRESSLIST_SETDEFAULT_SUCCESS:
    case types.ADDRESSLIST_DELETE_SUCCESS:
    case types.ADDRESSLIST_DELETE_FAILED:
    case types.ADDRESSLIST_SETDEFAULT_FAILED:
      return {
        ...state,
        initing: false,
        loading: false,
      };
    case types.ADDRESSLIST_UNMOUNT:
      return {
        ...initialState,
      };
    default:
      return state;
  }
}
